<!-- 附件下载 -->
<template>
	<div class="filestyle" @click="download">
		{{fileName}}
	</div>
</template>

<script>
    import axios from 'axios'
	export default {
		name: "fileDownload",
		props: {
			fileName: String, 
			filePath: String,
		},
		components: {},
		data() {
			return {
				headers: {
				token: window.sessionStorage.getItem('token')
			},
			};
		},
		created() {

		},
		methods: {
		  downLoad() {
			let params = {
				filePath: this.filePath,
				fileName: this.fileName
			}
			axios({method: 'post', url: '/member-security/file/fileDownloadCommon', headers:this.headers ,data: params, responseType: 'blob'}).then(res => {
					if (!res.data) {
					return;
					}
					if ("download" in document.createElement("a")) {
					let url = window.URL.createObjectURL(new Blob([res.data]));
					let link = document.createElement("a");
					link.style.display = "none";
					link.href = url;
					link.setAttribute("download", params.fileName);
					document.body.appendChild(link);
					link.click();
					} else {
					navigator.msSaveBlob(new Blob([res.data]), params.fileName);
					}
			})
		  },
		}
	};
</script>

<style scoped="" lang="scss">
	.filestyle {
		color: #3D80FF;
		cursor: pointer;
		text-decoration: underline;
	}
</style>
